package org.yang.loginunion.core.mobile;

import lombok.extern.java.Log;
import org.apache.commons.lang3.StringUtils;
import org.yang.loginunion.core.LoginClient;
import org.yang.loginunion.core.constants.IdentityType;
import org.yang.loginunion.core.exception.LoginException;
import org.yang.loginunion.core.mobile.request.ILocalMobileRequest;
import org.yang.loginunion.core.repository.OauthRepository;

/**
 * 本机号码一键登录
 *
 * @author Billyang
 * @date 2024/8/6 11:14
 */
public class LocalMobileClient implements LoginClient {

    private OauthRepository oauthRepository;
    private ILocalMobileRequest localMobileRequest;

    public LocalMobileClient(OauthRepository oauthRepository, ILocalMobileRequest localMobileRequest) {
        this.oauthRepository = oauthRepository;
        this.localMobileRequest = localMobileRequest;
    }
    @Override
    public String login(String accessToken, String ignore2, String ignore3) {
        if (StringUtils.isBlank(accessToken)) {
            throw new LoginException("缺失参数");
        }
        // 通过3大运营商获取本机手机号码，可直接使用
        String mobile = localMobileRequest.getMobile(accessToken);
        String userId = oauthRepository.registerUser(IdentityType.MOBILE, mobile);
        return userId;
    }
}
